//生产
var url="https://www.51songsong565.cn";
var ws_url="wss://www.51songsong565.cn/datafeed" //价格
var ws_user_url="wss://www.51songsong565.cn/websocket" //客服

//发送验证码倒计时
var time=180; 
//页面名称
var pageName ="your_investment";

//倒计时
function resetCode(){
	$('.gain_yzm').hide();
	$('#J_second').html('180');
	$('#J_resetCode').show();
	var second = 180;
	var timer = null;
	timer = setInterval(function(){
		second -= 1;
		if(second >0 ){
			$('#J_second').html(second);
		}else{
			clearInterval(timer);
			$('.gain_yzm').show();
			$('#J_resetCode').hide();
		}
	},1000);
}

function yzm(obj){
    if(time==0){
        obj.attr('disabled',false); 
        obj.text('获取验证码');
        time==180;
    }else{
        obj.attr('disabled',true); 
        obj.text(time+'s');
        time--;
    }
    setTimeout(function(){
        yzm(obj)
    },1000)
}

//根据时间戳生成的时间对象
function timestamp(data){
    var d = new Date(data);    
    var date = (d.getFullYear()) + "-" + 
               (d.getMonth() + 1) + "-" +
               (d.getDate()) + " " + 
               (d.getHours()) + ":" + 
               (d.getMinutes()) + ":" + 
               (d.getSeconds());
    return date;
}
function timestamp2(data){
    var d = new Date(data);    
    var date = (d.getFullYear()) + "-" + 
               (d.getMonth() + 1) + "-" +
               (d.getDate());
    return date;
}
function timestamp3(data){
    var d = new Date(data);    
    var date = (d.getHours()) + ":" + 
               (d.getMinutes()) + ":" + 
               (d.getSeconds());
    return date;
}
function timestamp4(data){
    var d = new Date(data);
    var date = (d.getFullYear()) + "/" +
        (d.getMonth() + 1) + "/" +
        (d.getDate()) + " " +
        (d.getHours()) + ":" +
        (d.getMinutes());
    var year=d.getFullYear();
    var month=d.getMonth() + 1;
    var day=d.getDate();
    var hour=d.getHours();
    var minutes=d.getMinutes();
    if(month<10)
        month="0"+month;
    if(day<10)
        day="0"+day;
    if(hour<10)
        hour="0"+hour;
    if(minutes<10)
        minutes="0"+minutes;
    var datestr=year+ "/" +month+ "/" +day+" "+hour+":"+minutes;
    return datestr;
}
function timestamp5(data){
    var d = new Date(data);    
    var date = (d.getMonth() + 1) + "/" +
               (d.getDate());
    return date;
}
//获取url?后的参数
function GetRequest() {
    var url = location.search; //获取url中"?"符后的字串
    var str;
    if (url.indexOf("?") != -1) {
        str = url.substr(1);
    }
    return  str;
}

//获取url?后的参数
function GetRequest2() {
    var url = location.search; //获取url中"?"符后的字串
    var str;
    if (url.indexOf("?") != -1) {
        str = url;
    }
    return  str;
}
function getUrlParameter(paramKey) {
    var sURLVariables, i, sParameterName, sPageURL = window.location.search.substring(1);
    if (sPageURL) {
        sURLVariables = sPageURL.split("&");
        for (i = 0; i < sURLVariables.length; i++) {
            sParameterName = sURLVariables[i].split("=");
            if (sParameterName[0] === paramKey) return sParameterName[1]
        }
    }
}
// 测试
// 473423608@qq.com
// 13127661900

//时间差
function gettime(date1,date2){
    var date3 = new Date(date2).getTime() - new Date(date1).getTime();   //时间差的毫秒数
    if(date3<0)
        date3=date3 *(-1);
    //计算出相差天数
    var days=Math.floor(date3/(24*3600*1000));
    //计算出小时数
    var leave1=date3%(24*3600*1000)    //计算天数后剩余的毫秒数
    var hours=Math.floor(leave1/(3600*1000))
    //计算相差分钟数
    var leave2=leave1%(3600*1000)        //计算小时数后剩余的毫秒数
    var minutes=Math.floor(leave2/(60*1000))
    //计算相差秒数
    var leave3=leave2%(60*1000)      //计算分钟数后剩余的毫秒数
    var seconds=Math.round(leave3/1000)
    return days+"天"+hours+"小时"+minutes+"分钟";
}
function gettime2(date3){
    if(date3<0){date3=date3 *(-1)};
    //计算出相差天数
    var days=Math.floor(date3/(24*3600*1000));
    //计算出小时数
    var leave1=date3%(24*3600*1000)    //计算天数后剩余的毫秒数
    var hours=Math.floor(leave1/(3600*1000))
    //计算相差分钟数
    var leave2=leave1%(3600*1000)        //计算小时数后剩余的毫秒数
    var minutes=Math.floor(leave2/(60*1000))
    //计算相差秒数
    var leave3=leave2%(60*1000)      //计算分钟数后剩余的毫秒数
    var seconds=Math.round(leave3/1000)
    return days+getMsg("天")+hours+getMsg("小时")+minutes+getMsg("分钟");
}

function computeSpread2(buy,sell,spread,volatility,callback){
    if(spread>0 && volatility != null){
    	buy = computeAsk(buy,spread,volatility);
    	sell = computeBid(sell,spread,volatility);
    	spread=showSpread(buy,sell,volatility);
    }else if(spread==0){
        buy=buy;
        sell=sell;
    }
    
    // 自己投页面
    $('.your_detail_topcen').find('.your_detail_topnum').eq(0).html(buy);
    $('.your_detail_topcen').find('.your_detail_topnum').eq(1).html(spread);
    $('.your_detail_topcen').find('.your_detail_topnum').eq(2).html(sell);

    // 订单详情页面
    $(".your_order_detail1 .price").html(buy);
    $(".your_order_detail1 .overPrice").html(sell);
    $(".your_order_detail1 .diancha").html(spread);

    //回调函数
    callback(buy,sell,spread)
}
//自定义加法运算
function addNum (num1, num2) {
     var sq1,sq2,m;
     try {
          sq1 = num1.toString().split(".")[1].length;
     }
     catch (e) {
          sq1 = 0;
     }
     try {
          sq2 = num2.toString().split(".")[1].length;
     }
     catch (e) {
          sq2 = 0;
     }
    m = Math.pow(10,Math.max(sq1, sq2));
    var zongNum=(num1 * m + num2 * m) / m

    var m2=m.toString().length-1

    return zongNum.toFixed(m2);
}
function timeDiff(date3) {
    //计算出相差天数
    var days = Math.floor(date3 / (24 * 3600 * 1000));
    if (days > 0) {
        return days + getMsg("天前")
    }
    //计算出小时数
    var leave1 = date3 % (24 * 3600 * 1000);    //计算天数后剩余的毫秒数
    var hours = Math.floor(leave1 / (3600 * 1000));
    if (hours > 0) {
        return hours + getMsg("小时前")
    }
    //计算相差分钟数
    var leave2 = leave1 % (3600 * 1000)        //计算小时数后剩余的毫秒数
    var minutes = Math.floor(leave2 / (60 * 1000));
    if (minutes > 0) {
        return minutes + getMsg("分钟前")
    }
    //计算相差秒数
    var leave3 = leave2 % (60 * 1000);      //计算分钟数后剩余的毫秒数
    var seconds = Math.round(leave3 / 1000);
    return seconds + getMsg("秒前")
}


/*
截取字符串*/
function substr(str,len){
  return  str.substr(str.length-len);
}

//加    
function floatAdd(arg1,arg2){    
    var r1,r2,m;    
    try{
        r1=arg1.toString().split(".")[1].length
    }catch(e){
        r1=0
    }    
    try{
        r2=arg2.toString().split(".")[1].length
    }catch(e){
        r2=0
    }    

   m = Math.pow(10,Math.max(r1, r2));
   var zongNum=(arg1 * m + arg2 * m) / m
   var m2=m.toString().length-1
   return zongNum.toFixed(m2);
}    
     
//减    
function floatSub(arg1,arg2){    
   var r1,r2,m,n;    
   try{
       r1=arg1.toString().split(".")[1].length
    }catch(e){
        r1=0
    }    
   try{
       r2=arg2.toString().split(".")[1].length
    }catch(e){
        r2=0
    }    
   m=Math.pow(10,Math.max(r1,r2));    
   //动态控制精度长度    
   n=(r1>=r2)?r1:r2;    
   return ((arg1*m-arg2*m)/m).toFixed(n);    
}    
      
//乘    
function floatMul(arg1,arg2)   {     
   var m=0,s1=arg1.toString(),s2=arg2.toString();     
   try{
       m+=s1.split(".")[1].length
    }catch(e){

    }     
   try{
       m+=s2.split(".")[1].length
    }catch(e){

    }     
   return Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m);     
}     
     
     
//除   
function floatDiv(arg1,arg2){     
     var t1=0,t2=0,r1,r2;     
     try{
         t1=arg1.toString().split(".")[1].length
        }catch(e){

        }     
     try{
         t2=arg2.toString().split(".")[1].length
        }catch(e){

        }     
       
     r1=Number(arg1.toString().replace(".",""));  
     r2=Number(arg2.toString().replace(".",""));     
     return (r1/r2)*Math.pow(10,t2-t1);     
}  
//除   
function floatDiv2(arg1,arg2){     
    var t1=0,t2=0,r1,r2;     
    try{
        t1=arg1.toString().split(".")[1].length
       }catch(e){

       }     
    try{
        t2=arg2.toString().split(".")[1].length
       }catch(e){

       }     
      
    r1=Number(arg1);  
    r2=Number(arg2);     
    return (r1/r2)*Math.pow(10,t2-t1);     
} 
//向上取整
function ceil(num){
    return Math.ceil(num);
}

//向下取整
function pasInt(num){
    return parseInt(num);
}

//用于图表计算
function symbolSpread(symbol,spread,volatility){
	var i = 0;
	if(spread == null || volatility == null || spread ==0){
		i = 0;
	}else{
		i = floatMul(ceil(floatDiv(spread,2)),volatility);
	}
    localStorage.setItem(symbol+"_total_spread",i);
}
//计算卖价
function computeBid(bid,spread,volatility){
	if(spread == null || volatility == null || spread ==0){
		return bid;
	}
    var i = floatMul(ceil(floatDiv(spread,2)),volatility);
    return  floatSub(bid,i);
}
//计算买价
function computeAsk(ask,spread,volatility){
	if(spread == null || volatility == null || spread ==0){
		return ask;
	}
    var i = floatMul(pasInt(floatDiv(spread,2)),volatility);
	return  floatAdd(ask,i);
}

//显示点差
function showSpread(ask,bid,volatility){
	return  Math.abs(floatDiv(floatSub(ask,bid),volatility));
}

//显示点差
function computeSpread(ask,bid,futureCode){
	var volatility = localStorage.getItem(futureCode + "_volatility");//交易步长
	return  Math.abs(floatDiv(floatSub(ask,bid),volatility));
}

//百度统计
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?4f015570e26db073c49092f60088175c";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
